module test_timer;

import dactor.scheduler;
import dactor.coroutine;
import dactor.eventlet;
import dactor.actor;
import std.stdio;

void timer_test(string name, int timeout) {
    while (true) {
        scope TimerEvent ev = new TimerEvent(timeout);
        writefln("begin wait: %s", name);
        int ret = ev.wait();
        writefln("wait result: %s, %d", name, ret);
        if (timeout == 1000) {
            writefln("=========================");
        }
    }
}

void sleeper() {
    while (true) {
        writefln("begin sleep");
        dactor.actor.sleep(1000);
        writefln("end sleep");
    }
}

void main() {
    spawn(&timer_test, "timer 1", 1000);
    spawn(&timer_test, "timer 2", 2000);
    spawn(&timer_test, "timer 3", 3000);
    spawn(&timer_test, "timer 4", 4000);
    spawn(&sleeper);

    Scheduler.instance.run();
}

